Skip to content

remove dependency on sorted_set#206

Merged
razumau merged 1 commit intomainfrom
jury.razumau/remove_sorted_set
Mar 5, 2026
Merged

remove dependency on sorted_set#206
razumau merged 1 commit intomainfrom
jury.razumau/remove_sorted_set

Conversation

@razumau
Copy link
Contributor

@razumau razumau commented Jan 12, 2026

sorted_set stopped working in Ruby after internal Set changes (changes description: https://bugs.ruby-lang.org/issues/21216, https://rubyreferences.github.io/rubychanges/4.0.html#set).

Set subclasses cannot use @hash anymore, which breaks the way sorted_set works (it replaces @hash with a red-black tree from rbtree).

We only need to preserve an ordered list of dependencies to build the same cache key every time (introduced in this commit: e132533). So, we can sort them before building a cache key and use a regular Set.

Alternatively, we could rebuild a new Set every time a dependency is added:

def dependencies
  return Set.new if self == Curly::Presenter
  @dependencies ||= Set.new
  Set.new(@dependencies.union(superclass.dependencies).sort)
end

def depends_on(*dependencies)
  @dependencies ||= Set.new
  Set.new(@dependencies.merge(dependencies).sort)

@razumau razumau force-pushed the jury.razumau/remove_sorted_set branch 2 times, most recently from b9947e0 to 2ee1aae Compare January 12, 2026 14:17
@razumau razumau force-pushed the jury.razumau/remove_sorted_set branch from 0010817 to 065793a Compare January 12, 2026 16:26
@razumau razumau marked this pull request as ready for review January 12, 2026 16:31
@razumau razumau requested a review from a team as a code owner January 12, 2026 16:31
@razumau razumau force-pushed the jury.razumau/remove_sorted_set branch from 065793a to 343bed7 Compare January 13, 2026 11:18
bquorning
bquorning previously approved these changes Jan 16, 2026
Copy link
Member

@bquorning bquorning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that SortedSet was introduced in order to fix “issues in the cache layer”, I think it makes sense to sort when we compute the (memoized) cache key instead of every time #dependencies is called.

However, we don’t know if any of our users are using #dependencies to calculate their own cache key – so maybe this is a breaking change?

@libo
Copy link

libo commented Jan 16, 2026

Yeah the breaking change issue was why I suggested to make the existing methods behave as before. Are we afraid of the cost of calling sort on every read? It's a O(n log n) where n won't be bigger than ~20 maybe 30...

@libo
Copy link

libo commented Jan 16, 2026

BTW original PR ...summer of 2014 #78

@razumau razumau force-pushed the jury.razumau/remove_sorted_set branch from d82cc1f to 2a52432 Compare January 21, 2026 11:04
sorted_set stopped working in Ruby after internal Set changes (changes description: https://bugs.ruby-lang.org/issues/21216, https://rubyreferences.github.io/rubychanges/4.0.html#set).

Set subclasses cannot use `@hash` anymore, which breaks the way `sorted_set` works (it replaces `@hash` with a red-black tree from `rbtree`).

We need to preserve an ordered list of dependencies to build the same cache key every time (introduced in this commit: e132533).

Since these lists are pretty short, and updates of these lists don’t happen on a hot path, an array that preserves the order is good enough. We will maintain uniqueness and sort order in both methods that update this array.
@razumau razumau force-pushed the jury.razumau/remove_sorted_set branch from 2a52432 to b053046 Compare March 5, 2026 14:34
@razumau razumau merged commit 8d4b8ef into main Mar 5, 2026
18 checks passed
@razumau razumau deleted the jury.razumau/remove_sorted_set branch March 5, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants